<?php

namespace App\Supports\Payment\Methods\Alibatch;

use Illuminate\Support\Facades\Log;
use App\Supports\Payment\Methods\Method;
use Illuminate\Validation\ValidationException;
use App\Supports\Payment\Contracts\MethodQuery;

class QueryWithdraw extends Method implements MethodQuery
{
	public function info($withdraw = null)
	{
		return [
			'out_batch_no' => $withdraw->batch->batch_number,
			'batch_no' => $withdraw->ali_batch_id,
			'product_code' => 'BATCH_API_TO_ACC_NO_PWD',
			'biz_scene' => 'MESSAGE_BATCH_PAY',
			'out_biz_no' => 'withdraw_'.$withdraw->number,
		];
	}

	public function query($withdraw = null)
	{
		$info = $this->info($withdraw);
		$result = $this->channel->query($info);

		if (empty($result->code) or $result->code != 10000) {
			throw ValidationException::withMessages(['err' => '支付宝记录查询异常']);
		}

		return $result;
	}
}
